package com.onpositive.datacollection.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISaveablePart;

import com.onpositive.datamap.core.IDataProperty;
import com.onpositive.semantic.model.api.changes.ISetDelta;
import com.onpositive.semantic.model.api.command.ICommand;
import com.onpositive.semantic.model.binding.IBindingChangeListener;
import com.onpositive.semantic.model.binding.ICommitListener;

public class PropertyDetails extends CollectionBasedSelectionView implements ISaveablePart, ICommitListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	IBindingChangeListener<Object> listener = new IBindingChangeListener<Object>() {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public void valueChanged(ISetDelta<Object> valueElements) {
			firePropertyChange(PROP_DIRTY);
		}

		@Override
		public void enablementChanged(boolean isEnabled) {
			
		}

		@Override
		public void changed() {
			firePropertyChange(PROP_DIRTY);
		}
	};
	public PropertyDetails() {
		super("propDetails.dlf");
		
		
	}
	@Override
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
		getBinding().addCommitListener(this);
		getBinding().addBindingChangeListener(listener);
	}
	@Override
	public void dispose() {
		super.dispose();
		getBinding().removeCommitListener(this);
		getBinding().removeBindingChangeListener(listener);
	}

	@Override
	protected Class getTargetClass() {
		return IDataProperty.class;
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		getBinding().commit();
	}

	@Override
	public void doSaveAs() {		
	}

	@Override
	public boolean isDirty() {
		return getBinding().isDeepDirty();
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	@Override
	public boolean isSaveOnCloseNeeded() {
		return false;
	}
	@Override
	public void commitPerformed(ICommand command) {
		firePropertyChange(PROP_DIRTY);
	}

}
